<?php

//error_reporting(0);

$c = curl_init("https://wechat.wecity.qq.com/api/THPneumoniaService/getHospitalProvince");
curl_setopt_array($c,[
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => "{\"args\":{\"req\":{}},\"service\":\"THPneumoniaOuterService\",\"func\":\"getHospitalProvince\",\"context\":{}}",
]);

$data = curl_exec($c);
$ps = json_decode($data,true)["args"]["rsp"]["provinces"];

//print_r($ps);

$f = fopen("fare_hospital.js","w");
fwrite($f,"var fare_hospitals = [\n");

$fdd = fopen("dingdian_hospital.js","w");
fwrite($fdd,"var dingdian_hospitals = [\n");

foreach ($ps as $p){ //省s
    $c = curl_init("https://wechat.wecity.qq.com/api/THPneumoniaService/getHospitalCityByProvince");
    curl_setopt_array($c,[
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => "{\"args\":{\"req\":{\"province\":\"{$p["provinceName"]}\",\"provinceCode\":\"\"}},\"service\":\"THPneumoniaOuterService\",\"func\":\"getHospitalCityByProvince\",\"context\":{}}",
    ]);

    $data = curl_exec($c);
    $cs = json_decode($data,true)["args"]["rsp"]["info"]["citys"];

//    print_r($cs);

    foreach ($cs as $city){ //市
        $c = curl_init("https://card.wecity.qq.com/feverHosp/feverHospList?cityCode={$city["cityCode"]}&pageIndex=1&pageSize=999&partnerType=4&lat=0&lng=0&searchKey=");
        curl_setopt_array($c,[
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
        ]);
        $data = curl_exec($c);
        $hs = json_decode($data,true)["data"]["data"];

        foreach ($hs as $h){
            if($h["isCore"]==1){fwrite($fdd,"{n:\"".$h["orgName"]."\",P:".$h["lat"].",Q:".$h["lng"]."},");}else{fwrite($f,"{n:\"".$h["orgName"]."\",P:".$h["lat"].",Q:".$h["lng"]."},");}
        }
    }
}

fwrite($f,"];");
fclose($f);
fwrite($fdd,"];");
fclose($fdd);

die();
